<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% rubric_summary ||= nil %>
<% rubric = rubric_summary %>
<% rubric_association ||= nil; editable ||= false; association_object = nil
   edit ||= false; rubic ||= nil; assessing ||= false; assessment ||= nil; brief ||= false %>
<div class="rubric_container rubric rubric_summary <%= 'free_form' if rubric && rubric.free_form_criterion_comments %>" id="<%= rubric ? "rubric_summary_#{rubric.id}" : "default_rubric_summary" %>" style="<%= 'hidden' unless brief %>">
  <div class="screenreader-only"><h3><%= t 'rubric', "Rubric" %></h3></div>
  <div class="rubric_title" style="<%= hidden if brief %>">
    <span class="title"><%= rubric.try(:title) || t('defaults.title', "Title") %></span>
    <span class="id" style="display: none;"><%= rubric.id rescue nbsp %></span>
  </div>
<table class="rubric_table">
<caption>
  <div class="screenreader-only">
    <span class="title"><%= rubric.try(:title) || t('defaults.title', "Title") %></span>
  </div>
</caption>
<thead>
  <tr>
    <th><%= t 'headers.criteria', "Criteria" %></th>
    <th><%= t 'headers.assessment', "Assessment" %></th>
  </tr>
</thead>
<tbody>
  <% if rubric && rubric.criteria %>
    <% rubric.criteria_object.each do |criterion| %>
      <% rating = assessment.ratings.find{|r| r.criterion_id == criterion.id} rescue nil %>
      {{> views/shared/rubric_summary_criterion}}
    <% end %>
  <% else %>
    {{> views/shared/rubric_summary_criterion}}
  <% end %>
  <tr class="summary" style="<%= hidden if rubric_association && rubric_association.hide_score_total %>">
    <td colspan="2" style="padding-right: 10px; text-align: right;">
      <%= before_label :total_points, "Total Points" %>
      <%= t "*%{points}* out of **%{total}**",
            points: (assessing ? "0" : (I18n.n(rubric.points_possible) rescue 5)),
            total: (I18n.n(rubric.points_possible) rescue 5),
            wrapper: {
              '*' => "<span class='rubric_total' style='#{hidden if brief}'>\\1</span>",
              '**' => "<span class='points_possible'>\\1</span>"
            }
      %>
    </td>
  </tr>
</tbody>
</table>
</div>
<div class="button-container" style="<%= hidden if brief %>">
  <button class="toggle_full_rubric edit btn"><%= t 'buttons.edit_assessment', "Edit Assessment" %></button>
</div>
